package com.rightsidetech.scheduler.task;

import com.rightsidetech.activity.service.MtActivityService;
import com.rightsidetech.system.service.SysCompanyAreaService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;
import java.util.List;

/**
 * 门店活动相关定时任务
 */
@Slf4j
@Component
@EnableScheduling
public class MtActivityTask {

    @Resource
    private MtActivityService mtActivityService;
    @Resource
    private SysCompanyAreaService sysCompanyAreaService;

    /**
     * 0点30分 执行门店活动到期  修改状态为结束
     */
    @Scheduled(cron = "0 30 0 * * ?")
    public void storeActivityTask() {
        try {
            //进行中的 到结束时间的修改状态
            mtActivityService.updateStatus();

        } catch (Exception e) {
            log.error("门店活动到期结束任务异常", e);
        }
    }

    /**
     * 0点 执行门店排名活动结算中奖排名
     */
    @Scheduled(cron = "0 0 0 * * ?")
    public void storeActivityRankingTask() {
        try {
            //查询大区id集合
            List<Long> ids = sysCompanyAreaService.allAreaId();
            mtActivityService.storeActivityRankingTask(ids);
        } catch (Exception e) {
            log.error("门店活动到期结算任务异常", e);
        }
    }

}
